package com.ym.jiujiangeyou.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;


/** 
* @author 叶铭
* @Description: 获取更新的版本号  
*/
public class PackageUtils {
	
	private Context context ;
	private PackageManager manager ;
	private PackageInfo packageInfo ;
	
	public PackageUtils(Context context) {
		this.context = context ;
		init() ;
	}
	
	
	public void init(){
		manager = context.getPackageManager() ;
		try {
			packageInfo = manager.getPackageInfo(context.getPackageName(),PackageManager.GET_ACTIVITIES) ;
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public int getVersionCode(){
		return packageInfo.versionCode ;
	}
	public String getVersionName(){
		return packageInfo.versionName ;
	}
	
	/** 
	* @param oldVersionCode
	* @param newVersionCode
	* @return  
	* @retur  boolean 
	* @Description: 判断是否需要更新
	*/
	public boolean isUpgrade(int oldVersionCode,int newVersionCode){
		boolean flag = newVersionCode > oldVersionCode?true:false ;
		return flag ;
	}
}
